﻿package game.exchangeddata 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import game.constants.ConstData;
	import game.events.EventData;
	import common.Utility;
	/**
	 * ...
	 * @author Nguyen Thi Bich Phuong (Daisy)
	 */
	public class TableInfo extends EventDispatcher {
		public var tableName:String = "";
		public var gameSet:int;
		public var gameNo:int;
		public var minBet:Number;
		public var maxBet:Number;
		public var bettingTime:int;
		public var message:String;
		public var status:String;
		public var dateGame:String = "";
		public var clockGame:String = "";
		
		
		/**
		 * @author Daisy
		 * @param	result
		 * @param	tableNo
		 * @usage This function is set table information: tableName, gameSet, gameNo
		 */
		public function returnSetBetStatus(result:String, tableNo:String):void {	
			this.tableName = Utility.trim(result.substr(ConstData.POS_BETSTATUS_TABLENAME, ConstData.LEN_BETSTATUS_TABLENAME));
			this.gameSet = parseInt(result.substr(ConstData.POS_BETSTATUS_GAMESET, ConstData.LEN_BETSTATUS_GAMESET));
			this.gameNo = parseInt(result.substr(ConstData.POS_BETSTATUS_GAMENO, ConstData.LEN_BETSTATUS_GAMENO));
			this.status = Utility.trim(result.substr(ConstData.POS_BETSTATUS_STATUS, ConstData.LEN_BETSTATUS_STATUS));
			dispatchEvent(new Event(EventData.UPDATE_TABLEINFO));	
			//trace("this.tableName:" + this.tableName + "result:" +result);
		}
		
		/**
		 * @author Daisy
		 * @param	minBet
		 * @param	maxBet
		 * @usage This function to set table information: minBet, maxBet
		 */
		public function setMinMaxBet(minBet:Number, maxBet:Number) {			
			this.minBet = minBet;
			this.maxBet = maxBet;
		}
		/**
		 * @author	Bamboo
		 * @param	result
		 */
		public function returnStartBet(result:String):void {			
			if(result != "0" ){
				this.gameSet = int(result.substr(ConstData.POS_BETSTART_GAMESET, ConstData.LEN_GAMESET));
				this.gameNo = int(result.substr(ConstData.POS_BETSTART_GAMENO, ConstData.LEN_GAMENO));		
				dispatchEvent(new Event(EventData.UPDATE_GAMESET_GAMENO));			
			}
		}
		
		public function returnDateClock(result:String):void {
			var temp:Array = result.split("-");
			this.dateGame = temp[0]+"/"+temp[1]+"/"+temp[2];
			this.clockGame = temp[3] + ":" + temp[4];
			dispatchEvent(new EventData(EventData.UPDATE_DATECLOCK));	
		}
	}
}